<template>
	<div class="content">
		<div class="clear">
			<Form :model="query" label-position="left" :label-width="100">
				<!--<Input v-model="query.id" class="w200 m-r10" placeholder="个人ID" />-->
				<Input v-model="query.userName" class="w200 m-r10" placeholder="获赠人用户名" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getConditionQuery">查询</Button>
			</Form>
		</div>
		<!--<fieldset>
			<legend>汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>累计转入：
								<span class="blue" v-text="walletInfo == null ? '0.00' : Fixed(walletInfo)">0</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>-->
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon>导出
		</Button>
		<Table stripe :columns="columns" :data="conditionQuery" ref="table" :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				dcShow: false,
				loading: true,
				jsonData: [],
				walletInfo: null, // 总钱包信息
				moneySummary: '', // 提币汇总
				dataValue: ['', ''], // 时间段值
				query: {
					id: '',
					tradeId: '',
					userName: '',
				},
				conditionQuery: [], // 条件查询的结果
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				current: 1,
				model: false,
				modal2: false,
				loading: true,
				modelIndex: '', // 审核成功时候需要用到的 ID
				value: '', // 审核失败的时候填入的值
				downList: [],
				detailList: [],
				columns: [
					//				{
					//						title: '个人ID',
					//						key: 'uuid',
					//						align: 'center',
					//						render: (h, params) => {
					//							return h('div', params.row.uuid == null ? '#' : params.row.uuid)
					//						}
					//					},
					//					{
					//						title: '登录名',
					//						key: 'userName',
					//						align: 'center',
					//						render: (h, params) => {
					//							return h('div', params.row.userName == null ? '#' : params.row.userName)
					//						}
					//					},
					{
						title: '转赠人用户名',
						key: 'tradeUserName',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.tradeUserName == null ? '#' : params.row.tradeUserName)
						}
					},
					{
						title: '获赠人用户名',
						key: 'userName',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.userName == null ? '#' : params.row.userName)
						}
					},
					{
						title: '到账数量',
						key: 'num',
						align: 'center',
						render: (h, params) => {
							return h('div', params.row.num == null ? '#' : this.Fixed(params.row.num, 4))
						}
					},
					{
						title: '币种类型',
						key: 'coinId',
						align: 'center',
						render: (h, params) => {
							return h('div', 'AIDT')
						}
					},
					{
						title: '创建时间',
						key: 'createTime',
						align: 'center',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					},
				]
			}
		},
		mounted() {
			this.$Message.config({ // 配置弹窗的位置
				top: 250
			})
			this.getQuery() // 提现审核列表查询
		},
		methods: {
			getQuery() { // 提现审核列表查询
				this.loading = true;
				let params = this.qs.stringify({
					pn: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
				})
				this.axios.post('/admin/accounting/withdraw/given', params).then(res => {
					if(res.data.code == 200) {
						this.conditionQuery = res.data.data.records;
						this.conditionQuery.forEach((row, index) => {
							this.conditionQuery[index].createTime = '\t' + this.conditionQuery[index].createTime;
							this.conditionQuery[index].coinId = this.conditionQuery[index].coinId == 0 ? 'USDT' : '#';
						})
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			cuctGetQuery(page) { // 提现审核列表分页查询
				this.loading = true;
				let params = this.qs.stringify({
					pn: page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.query.id, // 用户 uuid
					userName: this.query.userName,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'

				})
				this.axios.post('/admin/accounting/withdraw/given', params).then(res => {
					if(res.data.code == 200) {
						this.conditionQuery = res.data.data.records
						this.conditionQuery.forEach((row, index) => {
							this.conditionQuery[index].createTime = '\t' + this.conditionQuery[index].createTime;
							this.conditionQuery[index].coinId = this.conditionQuery[index].coinId == 0 ? 'USDT' : '#';
						})
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			getConditionQuery() { // 提现审核列表条件查询
				this.page = 1;
				this.loading = true;
				let params = this.qs.stringify({
					pn: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					userName: this.query.userName, // 转账编号
					uuid: this.query.id, // 用户 uuid
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})
				this.axios.post('/admin/accounting/withdraw/given', params).then(res => {
					if(res.data.code == 200) {
						this.conditionQuery = res.data.data.records
						this.conditionQuery.forEach((row, index) => {
							this.conditionQuery[index].createTime = '\t' + this.conditionQuery[index].createTime;
							this.conditionQuery[index].coinId = this.conditionQuery[index].coinId == 0 ? 'USDT' : '#';
						})
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			exportData() { // 导出
				this.jsonData = [];
				this.dcShow = true;
				this.axios.post('/admin/accounting/withdraw/given', this.qs.stringify({
					pn: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					userName: this.query.userName, // 转账编号
					uuid: this.query.id, // 用户 uuid
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.axios.post('/admin/accounting/withdraw/given', this.qs.stringify({
							pn: 1, // 当前页【可选，默认1】
							size: res.data.data.total, // 每页记录数【可选，默认20】
							userName: this.query.userName, // 转账编号
							uuid: this.query.id, // 用户 uuid
							startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
							endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
						})).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].tradeUserName = this.downList[index].tradeUserName == null ? '#' : this.downList[index].tradeUserName;
									this.downList[index].userName = this.downList[index].userName == null ? '#' : this.downList[index].userName;
									this.downList[index].num = this.downList[index].num == null ? '#' : this.downList[index].num;
									this.downList[index].coinId = this.downList[index].coinId == null ? '#' : this.downList[index].coinId;
									this.downList[index].createTime = this.downList[index].createTime == null ? '#' : this.downList[index].createTime;
									this.jsonData.push({
										tradeUserName: this.downList[index].tradeUserName,
										userName: this.downList[index].userName,
										num: this.Fixed(this.downList[index].num, 4),
										coinId: this.downList[index].coinId,
										createTime: this.downList[index].createTime,
									})
								})
								let str = `转赠人用户名,获赠人用户名,到账数量,币种类型,创建时间\n`;
								this.downLoad(this.jsonData, str, '获赠列表');
							}
						})
					}
				})
			},
			getTime(daterange) { // 处理时间段时间格式
				this.dataValue = daterange
			}
		}
	}
</script>